package com.springapp.service.impl;

import com.springapp.dao.dao.impl.ArticleDAO;
import com.springapp.model.Article;
import com.springapp.service.IArticlePickingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;

/**
 * Created by nicol_000 on 03/09/14.
 */
@Service
public class ArticlePickingService implements IArticlePickingService{

    @Autowired
    private ArticleDAO articleDao;

    private ArrayList<Article> lstArticlePickingAlertes;

    @PostConstruct
    public void init(){
        lstArticlePickingAlertes = articleDao.getListeArticles(true);
    }


    public ArrayList<Article> getLstArticlePickingAlertes(boolean _EstPicking){
        lstArticlePickingAlertes = articleDao.getListeArticles(_EstPicking);

        for(Article art : lstArticlePickingAlertes)
        {
           if(art.bEstAlerteOrange(art.geteQteTotale(),art.geteStockSecurite(),art.geteStockAlerte()))
           {
               art.setAlertOrange(true);
           }else if(art.bEstAlerteRouge(art.geteQteTotale(), art.geteStockAlerte()))
           {
               art.setAlertRouge(true);
           }
        }

        return lstArticlePickingAlertes;
    }

    @Override
    public String updateStocksPicking() {
        return articleDao.updatePicking(lstArticlePickingAlertes);
    }

}
